import datetime
import time
from apscheduler.schedulers.blocking import BlockingScheduler


def func():
 now = datetime.datetime.now()
 ts = now.strftime('%Y-%m-%d %H:%M:%S')
 print('do func time :', ts)


def func2():
 # 耗时2S
 now = datetime.datetime.now()
 ts = now.strftime('%Y-%m-%d %H:%M:%S')
 print('do func2 time：', ts)
 time.sleep(2)
 
def func3():
 # 耗时2S
 now = datetime.datetime.now()
 ts = now.strftime('%Y-%m-%d %H:%M:%S')
 print('do func3 time:', ts)
 time.sleep(2)


def dojob():
 # 创建调度器：BlockingScheduler
 scheduler = BlockingScheduler()
 # 添加任务,时间间隔2S
 scheduler.add_job(func, 'interval', seconds=2)
 # 添加任务,时间间隔3S+2S
 scheduler.add_job(func2, 'interval', seconds=3)
 # 添加任务,时间间隔4S+2S
 scheduler.add_job(func3, 'interval', seconds=4)
 scheduler.start()


dojob()
